package com.xonro.common.histrans.sfeg.job.update.contarct;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.schedule.IJob;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.xonro.common.histrans.base.consts.DrpConst;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.util.List;

public class UpdateContractSignNo implements IJob {


    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        List<RowMap> maps = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='C1' AND APPLY_NO!='HTQD-202210000001'");

        for(RowMap m:maps){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemC a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsD = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='D1' ");

        for(RowMap m:mapsD){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemD a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }


        List<RowMap> mapsE = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='E1' ");

        for(RowMap m:mapsE){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemE a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsF = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='F1' ");

        for(RowMap m:mapsF){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemF a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsG = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='G1' ");

        for(RowMap m:mapsG){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemG a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsH = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='H1' ");

        for(RowMap m:mapsH){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemH1 a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsI = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='I1' ");

        for(RowMap m:mapsI){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemI a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }

        List<RowMap> mapsL = DBSql.getMaps("SELECT ID,APPLY_NO  FROM BO_XR_CM_CONTRACT_SIGN WHERE CONTRACT_TYPE='L1' ");

        for(RowMap m:mapsL){
            String applyNo=m.getString("APPLY_NO");
            String id=m.getString("ID");
            RowMap mainMap = SDK.getCCAPI().getRDSAPI(DrpConst.ZZ_CCID).getMap("SELECT info.HTBH,info.ctName FROM tb_ContractInfo info  JOIN tb_ContractEconomicItemL a ON info.ctCode=a.ctCode    WHERE a.id = '" + applyNo + "'  ");
            String htbh=mainMap.getString("HTBH");
            String name=mainMap.getString("ctName");
            DBSql.update("UPDATE BO_XR_CM_CONTRACT_SIGN SET CONTRACT_NO='"+htbh+"',CONTRACT_NAME='"+name+"' WHERE ID='"+id+"'"  );
        }


    }


}
